/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ManageDpt.java
 *
 * Created on 21 févr. 2011, 22:32:08
 */

package fr.GCAM.StudentManager.UI.GUI;

import fr.GCAM.StudentManager.Business.Facade.FacadeDepartement;
import fr.GCAM.StudentManager.Business.POJO.Departement;
import fr.GCAM.StudentManager.Business.POJO.Etape;
import fr.GCAM.StudentManager.UI.AbstractUIFactory;
import javax.swing.JComponent;

/**
 * Classe definissant la GUI du departement
 * @author PIERRE
 */
public class GUIDepartement extends GUI<Departement> {

    private FacadeDepartement faDepa;
    private String dao;

    /** Creates new form ManageDpt */
    public GUIDepartement(String dao, String id) throws Exception {
        initComponents();
        this.dao = dao;
        faDepa = new FacadeDepartement(id, dao);

        nomDept.setText("Département : " + faDepa.getNomDepartement());
        versionDiplome.setText("Version diplôme : " + faDepa.getVersionDiplome());
        mnemo.setText(faDepa.getMnemo());
        for (Etape e : faDepa.getListeEtape()) {
            comboEtape.addItem(e);
        }

        setLocationRelativeTo(null);
	this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        comboEtape = new javax.swing.JComboBox();
        nomDept = new javax.swing.JLabel();
        mnemo = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        MnemoLabel = new javax.swing.JLabel();
        versionDiplome = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("GCAM StudentManager : Département");
        setResizable(false);

        jLabel1.setText("Année");

        nomDept.setText("Département : ");

        mnemo.setEditable(false);
        mnemo.setEnabled(false);

        jButton1.setText("Consulter");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        MnemoLabel.setText("Mnemo");

        versionDiplome.setText("Version diplôme :");

        jMenu1.setText("Fichier");

        jMenuItem1.setText("Quitter");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edition");

        jMenuItem2.setText("Préférences");
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(versionDiplome)
                    .addComponent(nomDept)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(MnemoLabel))
                        .addGap(55, 55, 55)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(comboEtape, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(mnemo, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 103, Short.MAX_VALUE)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(versionDiplome)
                .addGap(18, 18, 18)
                .addComponent(nomDept)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MnemoLabel)
                    .addComponent(mnemo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(comboEtape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        System.out.println("id=" + ((Etape)comboEtape.getSelectedItem()).getCodeEtape());
	try {
            AbstractUIFactory.getUIFactory("g").getUIEtape(dao, ((Etape)comboEtape.getSelectedItem()).getCodeEtape());
        } catch (Exception ex) {
            System.err.println("Erreur : " + ex);
	    ex.printStackTrace();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItem1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel MnemoLabel;
    private javax.swing.JComboBox comboEtape;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JTextField mnemo;
    private javax.swing.JLabel nomDept;
    private javax.swing.JLabel versionDiplome;
    // End of variables declaration//GEN-END:variables

}
